package web.Users;

import domain.Project;
import domain.Users;
import service.User_Service;
import service.impl.User_ServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/user_ProjectServlet")
public class User_ProjectServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置页面编码
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        HttpSession session = request.getSession();
        User_Service user_service = new User_ServiceImpl();

        String user_id = request.getParameter("user_id");
        String type = request.getParameter("type");

        /*查询用户角色和项目名称并填入session*/
/*        List<Users> role = user_service.findRole();
        session.setAttribute("role",role);*/
        List<Project> projects = user_service.findProject();
        session.setAttribute("project",projects);

        switch (Integer.parseInt(type))
        {
            case 0:
                request.getRequestDispatcher("/users/register.jsp").forward(request, response);
                break;
            case 1:
                request.setAttribute("user_id",user_id);
                request.getRequestDispatcher("receiveUserServlet").forward(request,response);
                break;
            case 2:
                request.getRequestDispatcher("/node/addNode.jsp").forward(request, response);

        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
